
#pragma once

#include <cstdio>
#include "sgldef.h"

class SglImage
{

public:

	SglImage();

	~SglImage();

	INT GetError(VOID) const;
	PSGLIMG GetHandle(VOID);
	BOOL Open(LPCTSTR pszFile, UINT nSubIdx);
	BOOL Open(LPCTSTR pszFile, PSGLHASH pHash);
	BOOL Close(VOID);

	static SglImage *FromHandle(PSGLIMG pHandle);

private:

	struct INDEX
	{
		union
		{
			UINT		nSubIdx;
			PSGLHASH	pHash;
		}		uIndex;
		BOOL	bFlag;
	};

	SGLIMG			m_Image;
	SGL_ERROR		m_Error;
	PTSTR			m_FilePath;
	DWORD			m_FrameNum;

	BOOL Open(LPCTSTR pszFile, INDEX &sIndex);
	BOOL LoadFile(FILE *pFile, INDEX &sIndex);
	BOOL LoadImage(FILE *pFile, INDEX &sIndex, DWORD dwSubNum, LPDWORD pOffTab, PSGLHASH pHashTab);
	BOOL LoadFrame(FILE *pFile, PSGLFRM pFrame);
	VOID ClearImage(VOID);
	VOID ClearFrame(PSGLFRM pFrame);

};
